package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {

    @Pointcut("execution(* com.itheima.dao.ResourceDao.openURL(*,*))")
    private void pt(){}

    @Around("pt()")
    public Object trimStr(ProceedingJoinPoint joinPoint) throws Throwable {

        Object[] args = joinPoint.getArgs();

        for (int i = 0; i < args.length; i++) {
            //判断参数是不是字符串
            if(args[i].getClass().equals(String.class)) {
                args[i] = args[i].toString().trim();
            }
        }

        Object result = joinPoint.proceed(args);

        return result;

    }
}
